package com.webserver.test;

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * @author 马强
 * @Description
 * @create 2022-04-15 14:15
 */
/*
*   java.io.ByteArrayOutputStream和ByteArrayInputStream
*   字节数组输出和输入流
*   它们是一队低级流，内部维护一个字节数组
*
*   ByteArrayOutputStream通过该流写出的数据会保存在内部维护的字节数组中*/
public class BAOSDemo {
    public static void main(String[] args) {
        ByteArrayOutputStream baos=new ByteArrayOutputStream();

        OutputStreamWriter osw= new OutputStreamWriter(baos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw= new PrintWriter(bw,true);

        pw.println("helloword");
        byte[] data =baos.toByteArray();

        System.out.println("内部数组长度"+data.length);
        System.out.println("内部数组内容"+ Arrays.toString(data));

        pw.println("think in java");
        data =baos.toByteArray();
        System.out.println("内部数组长度"+data.length);
        System.out.println("内部数组内容"+ Arrays.toString(data));
    }
}
